package com.wxapp.common.util.date;

import com.wxapp.common.util.check.CheckUtil;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
 * @author lgl
 * @Description localdatetime 工具类
 * @Datetime 2023/9/19 16:45
 * @Modified By
 */
public class LocalDateTimeUtil {

    public static final  String YYYY_MM_DD ="yyyy-MM-dd";
    public static final  String YYYYMMDD ="yyyyMMdd";
    public static final String HH_MM_SS = "HH:mm:ss";
    public static final String HHMMSS = "HHmmss";

    private LocalDateTimeUtil() {
    }
    /**
     * localDateTime 加 年月日时分秒
     */
    public static LocalDateTime addTime(final LocalDateTime now, final Integer num, final ChronoUnit chronoUnit) {
        if (CheckUtil.isNullObject(now) || CheckUtil.isNullObject(num) || CheckUtil.isNullObject(chronoUnit)){
            return null;
        }
        return now.plus(num,chronoUnit);
    }

    /**
     * TODO 两日期相差 年月日时分秒
     */
    public static Integer apartDate(final LocalDateTime one,final LocalDateTime two, final ChronoUnit chronoUnit){
        if (CheckUtil.isNullObject(one) || CheckUtil.isNullObject(two) || CheckUtil.isNullObject(chronoUnit)){
            return null;
        }
        return (int)chronoUnit.between(one, two);
    }

    public static String getNowStrLocalDateTime(){
       return getStrLocalDateTime(LocalDateTime.now(),YYYY_MM_DD+HH_MM_SS);
    }
    public static String getNowStrLocalDateTime(final String dateFormat){
        return getStrLocalDateTime(LocalDateTime.now(),dateFormat);
    }
    public static String getStrLocalDateTime(final LocalDateTime localDateTime){
        return getStrLocalDateTime(localDateTime,YYYY_MM_DD+HH_MM_SS);
    }
    public static String getStrLocalDateTime(final LocalDateTime localDateTime,final String dateFormat){
        return localDateTime.format(DateTimeFormatter.ofPattern(dateFormat));
    }
}
